#ifndef REMOTE_CONTROL_H
#define REMOTE_CONTROL_H

#include <stdint.h>
#include "usart.h"

#define RC_CH_VALUE_MIN         ((uint16_t)364)
#define RC_CH_VALUE_OFFSET      ((uint16_t)1024)
#define RC_CH_VALUE_MAX         ((uint16_t)1684)


#define RC_SW_UP                ((uint16_t)1)
#define RC_SW_MID               ((uint16_t)3)
#define RC_SW_DOWN              ((uint16_t)2)
//判断开关状态的宏
#define switch_is_down(s)       (s == RC_SW_DOWN)
#define switch_is_mid(s)        (s == RC_SW_MID)
#define switch_is_up(s)         (s == RC_SW_UP)

//按键状态
typedef union 
{
    struct 
    {
        uint16_t w      : 1;
        uint16_t s      : 1;
        uint16_t d      : 1;
        uint16_t a      : 1;
        uint16_t shift  : 1;
        uint16_t ctrl   : 1;
        uint16_t q      : 1;
        uint16_t e      : 1;
        uint16_t r      : 1;
        uint16_t f      : 1;
        uint16_t g      : 1;
        uint16_t z      : 1;
        uint16_t x      : 1;
        uint16_t c      : 1;
        uint16_t v      : 1;
        uint16_t b      : 1;
    };
    uint16_t keys;
} Key_t;

typedef struct 
{
    struct
    {
        int16_t left_horizontal;    //左摇杆水平方向
        int16_t left_vertical;      //左摇杆垂直方向
        int16_t right_horizontal;   //右摇杆水平方向
        int16_t right_vertical;     //右摇杆垂直方向
        int16_t side_dial;          //侧边拨轮

        uint8_t left_switch;        //左侧开关
        uint8_t right_switch;       //右侧开关
    } rc;

    struct
    {
        int16_t x;
        int16_t y;
        int16_t z;
        uint8_t press_l;
        uint8_t press_r;
    } mouse;
    
    //键盘按键 考虑shift和ctrl组合键 以后再说
    Key_t key[3];
} RC_ctrl_t;

RC_ctrl_t *RemoteControlInit(UART_HandleTypeDef *rc_usart_handle);
#endif
